import 'package:flutter/material.dart';
import 'package:flutter_sensor_backend/assets/color.dart';
import 'package:flutter_sensor_backend/assets/svg.dart';
import 'package:flutter_sensor_backend/component/bottom.dart';

class HomeList extends StatefulWidget {
  const HomeList({super.key});

  @override
  State<HomeList> createState() => _HomeListState();
}

class _HomeListState extends State<HomeList> {
  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async => false,
      child: Scaffold(
        appBar: AppBar(
          leading: Container(),
          title: Text(
            "iOT智能监测终端",
            style: TextStyle(
              color: os_black,
              fontSize: 16,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        body: ListView(
          // shrinkWrap: true,
          children: [
            // Container(height: 10),
            HomeBtn(img_path: "images/home/1.svg", url_path: "/data_collet"),
            HomeBtn(img_path: "images/home/2.svg", url_path: "/data_panel"),
            HomeBtn(img_path: "images/home/3.svg", url_path: "/data_collet"),
            HomeBtn(img_path: "images/home/4.svg", url_path: "/user_preview"),
            Container(height: 50),
            Bottom(),
          ],
        ),
      ),
    );
  }
}

class HomeBtn extends StatefulWidget {
  String img_path;
  String url_path;
  HomeBtn({
    super.key,
    required this.img_path,
    required this.url_path,
  });

  @override
  State<HomeBtn> createState() => _HomeBtnState();
}

class _HomeBtnState extends State<HomeBtn> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        Navigator.of(context).pushNamed(widget.url_path);
      },
      child: Container(
        margin: EdgeInsets.symmetric(horizontal: 10, vertical: 3.5),
        child: os_svg(
          path: widget.img_path,
          width: MediaQuery.of(context).size.width,
          height: MediaQuery.of(context).size.width * 104 / 347,
        ),
      ),
    );
  }
}
